/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：BattleOverScreen.java <br>
 * 创建时间：2013-8-6 下午5:41:02 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.battle;

import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.SavingScreen;
import lostland.gmud.exv2.battle.proc.BattleStart;
import lostland.gmud.exv2.battle.proc.holder.BattleHolder;
import lostland.gmud.exv2.blgframework.CScreen;
import lostland.gmud.exv2.data.Item;

/**
 * 类名：BattleOverScreen <br>
 * 说明：战斗结束
 *
 * @author 12548
 */
public class BattleOverScreen extends CScreen {

	public static boolean tpflag = false;
	public static boolean zdflag = true;

	public static void setZDFlag(boolean flag) {
		zdflag = flag;
	}

	public static void setTPFlag(boolean flag) {
		tpflag = flag;
	}



	public BattleOverScreen() {
		super();
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.CScreen#update(float)
	 */
	@Override
	public void update(float deltaTime) {

		if (Game.getInstance().data.auto_save) {
			new SavingScreen().save();
		}

		if (BattleScreen.getInstance().p1().getBattleData() != null) {
			BattleScreen.getInstance().p1().getBattleData().refresh();
		}
		if (BattleScreen.getInstance().p2().getBattleData() != null) {
			BattleScreen.getInstance().p2().getBattleData().refresh();
		}

		BattleScreen.getInstance().p1().setBattleData(null);
		BattleScreen.getInstance().p2().setBattleData(null);

		if (zdflag) {
			zdflag = false;
			return;
		}


		if (!BattleScreen.wflag) {
			if(Item.notNull(BattleStart.wp) && !Gmud.getNpc(BattleScreen.getInstance().enemyid).equips(BattleStart.wp)) {
				Gmud.getNpc(BattleScreen.getInstance().enemyid).equip(BattleStart.wp);
			}

			if(Item.notNull(BattleStart.wp0) && !Gmud.mc.equips(BattleStart.wp0)) {
				Gmud.mc.equip(BattleStart.wp0);
			}

			Gmud.mc.name = BattleStart.name;
		}


		if (tpflag) {
			zdflag = true;
			if (BattleScreen.getInstance().holder != null) {
				BattleScreen.getInstance().holder.battle_stat = BattleHolder.BATTLE_RUNAWAY;
			}
		} else {
			if(BattleScreen.getInstance().p1().getSp() > 0) {
				if (BattleScreen.getInstance().holder != null) {
					BattleScreen.getInstance().holder.battle_stat = BattleHolder.BATTLE_PLAYER1_WIN;
				}
			} else {
				if (BattleScreen.getInstance().holder != null) {
					BattleScreen.getInstance().holder.battle_stat = BattleHolder.BATTLE_PLAYER2_WIN;
				}
			}
		}

//		game.replaceCurrentScreen(Gmud.bs.holder);
		getGame().popScreen();

		zdflag = true;
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.CScreen#present(float)
	 */
	@Override
	public void present(float deltaTime) {
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.CScreen#pause()
	 */
	@Override
	public void pause() {
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.CScreen#resume()
	 */
	@Override
	public void resume() {
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.CScreen#dispose()
	 */
	@Override
	public void dispose() {
	}

}
